package me.lc.superDown.core;

import me.lc.superDown.MainActivity;
import me.lc.superDown.R;
import android.app.Activity;
import android.content.SharedPreferences;

import com.wiyun.engine.nodes.CharMap;
import com.wiyun.engine.opengl.Texture2D;
import com.wiyun.engine.sound.AudioManager;
import com.wiyun.engine.types.WYRect;
import com.wiyun.engine.utils.ResolutionIndependent;
import com.wiyun.game.WiGame;

public class GameSystem {
	public static final String WiGameAppKey = "aec0c70844462a7d";

	public static final String WiGameSecretKey = "CMRhmu8MG87pt7XCtXchJqqkeFeVxkgb";

	public static final float RunSpeed = ResolutionIndependent.resolveDp(25);

	public static final float MaxMoveUnit = ResolutionIndependent.resolveDp(16);

	public static float PlatformMoveUnit = ResolutionIndependent.resolveDp(3);

	public static MainActivity AndroidContext;

	public static SharedPreferences SharedSettings;

	/**
	 * 屏幕宽度
	 */
	public static float Screen_Width = 0;

	/**
	 * 屏幕高度
	 */
	public static float Screen_Height = 0;

	public static Texture2D tex_bg;
	public static Texture2D tex_mainbg;
	public static Texture2D tex_finishBg;
	public static Texture2D tex_pauseBg;

	public static Texture2D tex_platformNormal;
	public static Texture2D tex_platformMini;
	public static Texture2D tex_platformSpeedDown;
	public static Texture2D tex_platformBreak;
	public static Texture2D tex_platformHit;
	public static Texture2D tex_platformBreakAction;

	public static Texture2D tex_manFaceRight;
	public static Texture2D tex_manFaceLeft;

	public static Texture2D tex_coin;
	public static Texture2D tex_flower;
	public static Texture2D tex_speed_up;
	public static Texture2D tex_speed_down;
	public static Texture2D tex_new_record;

	public static Texture2D tex_clock;
	public static Texture2D tex_number;
	public static Texture2D tex_help;
	public static CharMap charMap;

	public static void loadAllResource() {
		initSetting();
		loadTexture();
		initCharMap();
		loadSound();
	}

	private static void loadSound() {
		// AudioManager.preloadBackgroundMusic(R.raw.game_music);
		AudioManager.preloadEffect(R.raw.click);
		AudioManager.preloadEffect(R.raw.finish);
		AudioManager.preloadEffect(R.raw.getcoin);
		AudioManager.preloadEffect(R.raw.speedtool);
		AudioManager.preloadEffect(R.raw.land);
	}

	private static void initSetting() {
		SharedSettings = AndroidContext.getPreferences(Activity.MODE_PRIVATE);
	}

	private static void initCharMap() {
		charMap = CharMap.make();
		charMap.mapChar(WYRect.make(0, 0, ResolutionIndependent.resolveDp(20),
				ResolutionIndependent.resolveDp(25)), '0');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(20), 0,
				ResolutionIndependent.resolveDp(10),
				ResolutionIndependent.resolveDp(25)), '1');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(30), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '2');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(51), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '3');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(72), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '4');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(93), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '5');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(114), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '6');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(135), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '7');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(156), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '8');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(177), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '9');
	}

	private static void loadTexture() {
		tex_platformNormal = Texture2D.makePNG(R.drawable.platform_normal);
		tex_platformMini = Texture2D.makePNG(R.drawable.platform_mini);
		tex_platformBreak = Texture2D.makePNG(R.drawable.platform_break);
		tex_manFaceRight = Texture2D.makePNG(R.drawable.man_face_right);
		tex_manFaceLeft = Texture2D.makePNG(R.drawable.man_face_left);
		tex_platformBreakAction = Texture2D
				.makePNG(R.drawable.platform_break_action);
		tex_platformSpeedDown = Texture2D
				.makePNG(R.drawable.platform_speeddown);

		tex_coin = Texture2D.makePNG(R.drawable.coin);
		tex_flower = Texture2D.makePNG(R.drawable.flower);
		tex_speed_up = Texture2D.makePNG(R.drawable.speed_up);
		tex_speed_down = Texture2D.makePNG(R.drawable.speed_down);

		tex_bg = Texture2D.makePNG(R.drawable.bg);
		tex_clock = Texture2D.makePNG(R.drawable.clock);
		tex_number = Texture2D.makePNG(R.drawable.number);

		tex_mainbg = Texture2D.makePNG(R.drawable.main);
		tex_finishBg = Texture2D.makePNG(R.drawable.win_bg);
		tex_pauseBg = Texture2D.makePNG(R.drawable.pause_bg);

		tex_new_record = Texture2D.makePNG(R.drawable.new_record);
		tex_help = Texture2D.makePNG(R.drawable.help);

		// load
		tex_help.loadTexture();
		tex_new_record.loadTexture();
		tex_pauseBg.loadTexture();
		tex_finishBg.loadTexture();
		tex_mainbg.loadTexture();
		tex_number.loadTexture();
		tex_clock.loadTexture();
		tex_speed_up.loadTexture();
		tex_speed_down.loadTexture();
		tex_flower.loadTexture();
		tex_bg.loadTexture();
		tex_coin.loadTexture();
		tex_platformSpeedDown.loadTexture();
		tex_platformBreakAction.loadTexture();
		tex_platformBreak.loadTexture();
		tex_platformMini.loadTexture();
		tex_platformNormal.loadTexture();
		tex_manFaceRight.loadTexture();
		tex_manFaceLeft.loadTexture();
	}
}
